< previous page page_822 next page >

Page 822
Listing 21.26. continued
        db.Close
        ws.Close
        Set db = Nothing
        Set ws = Nothing
    End If
    '
    accLoadLists
    '
End Sub
Notice that you use an SQL statement to perform this task. Because you are using the Execute method, you need to open another copy of the database. Also, because the single SQL statement might be deleting multiple records in the same table, you encapsulate the delete process in a BeginTrans_CommitTrans loop.
Now for the hardest one of the bunch, the accCopyAll routine. Because some records might already be on file, you first must delete any existing items. The routine in Listing 21.27 contains several SQL statements and, of course, they are covered by Visual Basic transactions, too.
Type.gifListing 21.27. The accCopyAll routine.
Public Sub accCopyAll()
    '
    ' copy all objects from default to user
    '
    Dim strUserID As String
    Dim strSQLDelete As String
    Dim strSQLTemp As String
    Dim strSQLUpdate As String
    Dim strSQLDrop As String
    Dim strSQLInsert As String
    Dim intAnswer As Integer
    Dim ws As Workspace
    Dim db As Database
    '
    ' init vars
    strUserID = lblUserID
    strSQLDelete = "DELETE FROM secAccess WHERE UserID='" & strUserID & "'"
    strSQLTemp = "SELECT * INTO secTemp FROM secAccess WHERE UserID='DEFAULT'"
    strSQLUpdate = "UPDATE secTemp SET UserID='" & strUserID & "'"
    strSQLInsert = "INSERT INTO secAccess SELECT * FROM secTemp"
    strSQLDrop = "DROP Table secTemp"
    '
    ' now do it
    intAnswer = MsgBox("Replace all current objects for UserID [" & strUserID &
"]?", vbQuestion + vbYesNo, "CopyAll")
    If intAnswer = vbYes Then
        '
        Set ws = DBEngine.CreateWorkspace("wsCopyAll", "admin", "")
        Set db = ws.OpenDatabase(strDBName)
        '

 
< previous page page_822 next page >

If you like this book, buy it!